import { createRouter, createWebHashHistory } from "vue-router";
import transitionExtend from "./transition-extend";

// 首页
const Home = () => import("../view/Home/Home.vue")
const HomeRec = () => import("../view/Home/child/HomeRec.vue")
const HomeDyn = () => import("../view/Home/child/HomeDyn.vue")
// 文章详情
const ArtDetail = () => import('../view/ArtDetail/ArtDetail.vue')
// 社区
const Community = () => import('../view/Community/Community.vue')
const CommunityRecommend = () => import('../view/Community/child/CommunityRecommend.vue')
const CommunityHotList = () => import('../view/Community/child/CommunityHotList.vue')

// 我的
const Profile = () => import('../view/Profile/Profile.vue')
const Setting = () => import('../view/Profile/Setting.vue')
// 登录注册 
const LoginRegister = () => import('../view/LoginRegister/LoginRegister.vue')

// 游戏库
const GameStore = () => import('../view/GameStore/GameStore.vue')
const GameRec = () => import('../view/GameStore/child/GameRecommend.vue')
const GameRank = () => import('../view/GameStore/child/GameRank.vue')

// 游戏详情
const GameDetail = () => import('../view/GameDetail/GameDetail.vue')

// 购物车
const ShoppingCart = () => import('../view/ShoppingCart/ShoppingCart.vue')
// 购物结算
const Settlement = () => import('../view/Settlement/Settlement.vue')

// 收货地址
const AddressList = () => import('../view/AddressList/AddressList.vue')

// 文章发布
const PublishArticles = () => import('../view/PublishArticles/PublishArticles.vue')

const routes = [
  { path: '/', redirect: '/home' },
  // 首页
  {
    path: '/home',
    redirect: '/home/rec',
    name: 'home',
    meta: {
      keepAlive: true, // 设置页面是否需要使用缓存
    },
    component: Home,
    children: [{
      path: 'rec', // 首页推荐页面
      name: 'homerec',
      meta: {
        keepAlive: true,
      },
      component: HomeRec
    }, {
      path: 'dyn', // 首页动态页面
      name: 'homedyn',
      meta: {
        keepAlive: true,
      },
      component: HomeDyn
    }]
  },
  // 社区
  {
    path: '/community',
    redirect: '/community/rec',
    name: 'community',
    meta: {
      keepAlive: true,
    },
    component: Community,
    children: [{
      path: 'rec', // 社区推荐页面
      name: 'communityrecommend',
      meta: {
        keepAlive: true,
      },
      component: CommunityRecommend
    }, {
      path: 'hotlist', // 社区热榜页面
      name: 'communityhotList',
      meta: {
        keepAlive: true,
      },
      component: CommunityHotList
    }]
  },
  // 文章详情
  {
    path: '/artdetail',
    name: 'artdetail',
    component: ArtDetail
  },
  // 游戏库
  {
    path: '/gamestore',
    redirect: '/gamestore/rec',
    name: 'gamestore',
    meta: {
      keepAlive: true,
    },
    component: GameStore,
    children: [{
      path: 'rec', // 游戏库推荐页面
      name: 'gamestorerec',
      meta: {
        keepAlive: true,
      },
      component: GameRec
    }, {
      path: 'rank', // 游戏库榜单页面
      name: 'gamestorerank',
      meta: {
        keepAlive: true,
      },
      component: GameRank
    }]
  },
  // 游戏详情
  {
    path: '/gamedetail',
    name: 'gamedetail',
    component: GameDetail
  },
  // 我的
  {
    path: '/profile',
    name: 'profile',
    component: Profile,
  },
  // 设置
  {
    path: '/setting',
    name: 'setting',
    component: Setting,
  },
  // 登录注册
  {
    path: '/login',
    name: 'login',
    component: LoginRegister
  },
  // 购物车
  {
    path: '/shoppingcart',
    name: 'shoppingcart',
    component: ShoppingCart
  },
  // 购物结算
  {
    path: '/settlement',
    name: 'settlement',
    component: Settlement
  },
  // 收货地址
  {
    path: '/addresslist',
    name: 'addresslist',
    component: AddressList
  },
  // 文章发布
  {
    path: '/publisharticles',
    name: 'publisharticles',
    component: PublishArticles
  },
]

let router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 对router对象扩展
// router = transitionExtend(router)
export default router